package com.my.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import cn.hutool.json.JSONObject;
import com.my.R;
import com.my.activity.NightSpotListActivity;
import com.my.adapter.entity.NightSpot;

import java.util.List;

public class NightSpotAdapter extends ArrayAdapter<JSONObject> {

    private int resourceId;

    public NightSpotAdapter(@NonNull Context context, int resource, @NonNull List<JSONObject> objects) {
        super(context, resource, objects);
        this.resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        JSONObject spot  = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);
        ((TextView) view.findViewById(R.id.u_name)).setText(spot.getStr("userName"));
        ((TextView) view.findViewById(R.id.grade_class)).setText(spot.getStr("gradeName") + spot.getStr("className"));
        ((TextView) view.findViewById(R.id.createTime)).setText(spot.getStr("createTime"));
        ((TextView) view.findViewById(R.id.status)).setText(spot.getInt("status") == 1 ? "待审核" : (spot.getInt("status") == 2 ? "通过" : "未通过"));
        return view;
    }
}
